﻿@model IEnumerable<GameSchool.Models.OnTheFlyModels.CourseOverviewItem>

@{
    GameSchool.Models.Person loggedOnPerson;
    loggedOnPerson = GameSchool.Extra.UserInfo.GetLoggedOnPerson();
    bool isAdmin = (loggedOnPerson != null && loggedOnPerson.IsAdmin);
    bool isTeacher = (loggedOnPerson != null && loggedOnPerson.IsTeacher);
    bool isStudent = (loggedOnPerson != null && loggedOnPerson.IsStudent);
   }

@{
    ViewBag.Title = "Námskeið";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@if (ViewData.ContainsKey("HasCreateNewAccess") && (bool) ViewData["HasCreateNewAccess"])
{
    <text>
        <p>
            @Html.ActionLink("Búa til nýtt námskeið", "CreateCourse")
        </p>
    </text>
}

@if (ViewData.ContainsKey("RegisterResult"))
{
    <text>
        <p>
           @ViewData["RegisterResult"]
        </p>
    </text>
}

@if (Model != null)
{
	<text>
		<table>
			<tr>
             @if (isStudent)
             {
				<th>
					&nbsp;
				</th>
             }
				<th>
					Námskeið
				</th>
				<th>
					Lýsing
				</th>
				<th>
					ECTS
				</th>
                 @if (isTeacher || isAdmin)
                {
                    <th>
					    Breytingar
				    </th>
                }

			</tr>

			@foreach (var item in Model)
			{
				<tr>
                    @if (isStudent)
                    {
					    <td>
						    @if (item.RegType == GameSchool.Extra.CustomTypes.CourseRegType.Student)
						    {
							    <br />
							    <a href="/Course/DetailsCourse/@(item.CourseId)">							
                                    <span class="ui-icon ui-icon-circle-check" style="float: left; cursor: pointer;" title="Opna námskeið - vinna verkefni"></span>
                                </a>
                            }
						    @if (item.RegType == GameSchool.Extra.CustomTypes.CourseRegType.Teacher)
                            {
							    <span class="ui-icon ui-icon-wrench" style="float: left; cursor: pointer;" title="Skoða sem kennari"></span>
                             }
						    @if (item.RegType == GameSchool.Extra.CustomTypes.CourseRegType.NotParticipating)
                            {
							    <br />
							    <a href="/Course/StudentRegisterForCourse/@(item.CourseId)">
								    <span class="ui-icon ui-icon-play" style="float: left; cursor: pointer;" title="Taka þátt í námskeiði"></span>
							    </a>
                            }
						    @if (item.RegType == GameSchool.Extra.CustomTypes.CourseRegType.Completed)
                            {
							    <br />
							    <span class="ui-icon ui-icon-star" style="float: left; cursor: pointer;" title="Námskeiði lokið!"></span>
                            }
					</td>
                   }     
					<td>
						@Html.DisplayFor(modelItem => item.CourseName)
					</td>
					<td>
						@Html.DisplayFor(modelItem => item.CourseDescription)
					</td>
					<td>
						@Html.DisplayFor(modelItem => item.CourseECTS)
					</td>
                     @if (isTeacher || isAdmin)
                    {
                        <td>
						    @Html.ActionLink("Breyta", "EditCourse/", new { id = Html.DisplayFor(modelItem => item.CourseId) })
					    </td>
                    }
				</tr>
            }
		</table>
	</text>
}
